use std::thread;
use std::thread::sleep;
use std::time::Duration;

fn main() {
    // let a  = 10;
    // let b  = 20;
    // println!("The value of a is: {}", a);

    // tokio::runtime::Builder::new_multi_thread().enable_all().build().unwrap().block_on(async {
    //
    // })

    let handle = thread::spawn(|| {
        // println!("abc");
        //execute future?
        let rt = tokio::runtime::Builder::new_current_thread()
            .enable_all()
            .build()
            .unwrap();
        rt.spawn(async {
            println!("future1");
            let content = tokio::fs::read_to_string("README.md").await.unwrap();
            println!("content: {content}");
        });

        rt.spawn(async {
            println!("future2");

            let ret = expensive_blocking_task("Future 2".to_string());
            println!("ret: {ret:?}");
        });

        rt.block_on(async {
            tokio::time::sleep(Duration::from_secs(3)).await;
            println!("hello world");
        });
    });

    handle.join().unwrap();
}

fn expensive_blocking_task(s: String) -> String {
    sleep(Duration::from_secs(2));
    s
}
